package com.situ.crm.observer;

import java.util.ArrayList;
import java.util.List;

public class Subject {
    private List<Observer> observers = new ArrayList<>();

    //addObserver
    public void attach(Observer observer) {
        observers.add(observer);
    }

    //deleteObserver
    public void detach(Observer observer) {
        observers.remove(observer);
    }

    //当目标对象变化的时候，通知所有的观察者
    public void notifyObservers() {
        for (Observer observer : observers) {
            observer.update(this);
        }
    }
}
